home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13019 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  43 lines

  1. Path: netnews.cc.wwu.edu!news
  2. From: Kiet Lam <n9448673@henson.cc.wwu.edu>
  3. Newsgroups: comp.lang.c++
  4. Subject: Can't compile template class with g++
  5. Date: Fri, 22 Mar 1996 16:23:18 -0800
  6. Organization: Western Washington University
  7. Message-ID: <31534476.1A120953@henson.cc.wwu.edu>
  8. NNTP-Posting-Host: gonzo.cc.wwu.edu
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0 (X11; I; Linux 1.2.8 i486)
  13.  
  14. I am having problem compiling the following codes under Linux 1.2.8
  15. with g++ compiler.
  16.  
  17. template <class ET> class CTemplate {
  18.    public:
  19.       CTemplate(ET Init);
  20.       void Show(void);
  21.    protected:
  22.    private:
  23.       ET InitValue;
  24. };
  25.  
  26. CTemplate::CTemplate(ET Init) { //compiler complains at this line
  27.    InitValue = Init;
  28. }
  29.  
  30. void CTemplate::Show(void) { //compiler complains at this line too
  31.    cout << "InitValue = " << InitValue << endl;
  32. }
  33.  
  34. When the compiler gets to the constructor and the function, it output 
  35. the messages
  36.  
  37. parse error before `::'
  38.  
  39. Am I missing something?  I removed the template declaration and 
  40. replaced ET with int and the program compiled.  It also compiled when
  41. I kept the template declaration and moved the function body inside 
  42. the template class specifation.
  43.